@using WL.Think.Abp.Localization
@inject AbpBlazorMessageLocalizerHelper<ThinkResource> LH
@inherits Volo.Abp.AspNetCore.Components.AbpComponentBase
<Modal @ref="modal"  Closing="@ClosingModal">
    <ModalContent Size="ModalSize.Large" Centered="true">
        <ModalHeader>
            <ModalTitle>@Title</ModalTitle>
            <CloseButton Clicked="CloseAsync" />
        </ModalHeader>
        <ModalBody Overflow="Overflow.Hidden">
            <Validations @ref="@ValidationsRef" Model="@Entity" ValidateOnLoad="false">
                <Tabs SelectedTab="@SelectedTab" SelectedTabChanged="@OnSelectedTabChanged">
                    <Items>
                        <Tab Name="basic">@L["Basic"]</Tab>
                        <Tab Name="setting">@L["Setting"]</Tab>
                        <Tab Name="url">@L["Application URLs"]</Tab>
                        <Tab Name="scope">@L["Allowed Scope"]</Tab>
                    </Items>
                    <Content>
                        <TabPanel Name="basic">
                            <Validation MessageLocalizer="@LH.Localize">
                                <Field>
                                    <FieldLabel>@L[ThinkResourceNames.Name]</FieldLabel>
                                    <TextEdit @bind-Text="@Entity.ClientId" Autofocus="@(IsEditMode == false)" ReadOnly="@IsEditMode">
                                        <Feedback>
                                            <ValidationError></ValidationError>
                                        </Feedback>
                                    </TextEdit>
                                </Field>
                            </Validation>
                            <Validation MessageLocalizer="@LH.Localize">
                                <Field>
                                    <FieldLabel>@L[ThinkResourceNames.DisplayName]</FieldLabel>
                                    <TextEdit @bind-Text="@Entity.DisplayName">
                                        <Feedback>
                                            <ValidationError></ValidationError>
                                        </Feedback>
                                    </TextEdit>
                                </Field>
                            </Validation>
                            <Validation MessageLocalizer="@LH.Localize">
                                <Field>
                                    <FieldLabel>@L["ClientSecret"]</FieldLabel>
                                    <TextEdit @bind-Text="@Entity.ClientSecret" Role="TextRole.Password">
                                        <Feedback>
                                            <ValidationError></ValidationError>
                                        </Feedback>
                                    </TextEdit>
                                </Field>
                            </Validation>
                            <Field>
                                <FieldLabel>@L["ClientUri"]</FieldLabel>
                                <TextEdit @bind-Text="@Entity.ClientUri"></TextEdit>
                            </Field>
                            <Field>
                                <FieldLabel>@L["LogoUri"]</FieldLabel>
                                <TextEdit @bind-Text="@Entity.LogoUri"></TextEdit>
                            </Field>
                        </TabPanel>
                        <TabPanel Name="setting">
                            <Field>
                                <FieldLabel>@L["ClientType"]</FieldLabel>
                                <RadioGroup TValue="string" Name="ClientType" @bind-CheckedValue="@Entity.ClientType" Color="Color.Success">
                                    <Radio Value="@("public")">Public</Radio>
                                    <Radio Value="@("confidential")">Confidential</Radio>
                                </RadioGroup>
                            </Field>
                            <Field>
                                <FieldLabel>@L["ApplicationType"]</FieldLabel>
                                <RadioGroup TValue="string" Name="ApplicationType" @bind-CheckedValue="@Entity.ApplicationType" Color="Color.Success">
                                    <Radio Value="@("native")">Native</Radio>
                                    <Radio Value="@("web")">Web</Radio>
                                </RadioGroup>
                            </Field>
                            <Field>
                                <FieldLabel>@L["ConsentType"]</FieldLabel>
                                <RadioGroup TValue="string" Name="ConsentType" @bind-CheckedValue="@Entity.ConsentType" Color="Color.Success">
                                    <Radio Value="@("explicit")">Explicit</Radio>
                                    <Radio Value="@("external")">External</Radio>
                                    <Radio Value="@("implicit")">Implicit</Radio>
                                    <Radio Value="@("systematic")">Systematic</Radio>
                                </RadioGroup>
                            </Field>
                            <Field>
                                <FieldLabel>@L["GrantType"]</FieldLabel>
                                <Check TValue="bool" Checked="@(Entity.GrantTypes.Contains("authorization_code"))" CheckedChanged="@(b => OnGrantTypeChanged(b, "authorization_code"))">Authorization Code</Check>
                                <Check TValue="bool" Checked="@(Entity.GrantTypes.Contains("client_credentials"))" CheckedChanged="@(b => OnGrantTypeChanged(b, "client_credentials"))">Client Credentials</Check>
                                <Check TValue="bool" Checked="@(Entity.GrantTypes.Contains("urn:ietf:params:oauth:grant-type:device_code"))" CheckedChanged="@(b => OnGrantTypeChanged(b, "urn:ietf:params:oauth:grant-type:device_code"))">Device Code</Check>
                                <Check TValue="bool" Checked="@(Entity.GrantTypes.Contains("implicit"))" CheckedChanged="@(b => OnGrantTypeChanged(b, "implicit"))">Implicit</Check>
                                <Check TValue="bool" Checked="@(Entity.GrantTypes.Contains("password"))" CheckedChanged="@(b => OnGrantTypeChanged(b, "password"))">Password</Check>
                                <Check TValue="bool" Checked="@(Entity.GrantTypes.Contains("refresh_token"))" CheckedChanged="@(b => OnGrantTypeChanged(b, "refresh_token"))">Refresh Token</Check>
                            </Field>
                        </TabPanel>
                        <TabPanel Name="url">
                            <Field>
                                <FieldLabel>@L["Redirect Urls"]</FieldLabel>
                                <Div Class="d-flex flex-column border border-white mb-2">
                                    @if (Entity.RedirectUris.Any())
                                    {
                                        foreach (var item in Entity.RedirectUris)
                                        {
                                            <Badge Color="Color.Light"
                                                   Class="d-flex flex-row rounded-0 fs-6 justify-content-between mt-1"
                                                   CloseClicked="@(() => Entity.RedirectUris.Remove(item))">@item</Badge>
                                        }
                                    }
                                </Div>
                                <Addons>
                                    <Addon AddonType="AddonType.Body">
                                        <TextEdit Placeholder="@(L["Enter a valid URL address"])" @bind-Text="RedirectUrl" />
                                    </Addon>
                                    <Addon AddonType="AddonType.End">
                                        <Button Color="Color.Success" Clicked="@OnRedirectUrisClicked">@L["Add"]</Button>
                                    </Addon>
                                </Addons>
                            </Field>
                            <Field>
                                <FieldLabel>@L["Logout Redirect Urls"]</FieldLabel>
                                <div class="d-flex flex-column border border-white mb-2">
                                    @if (Entity.PostLogoutRedirectUris.Any())
                                    {
                                        foreach (var item in Entity.PostLogoutRedirectUris)
                                        {
                                            <Badge Color="Color.Light"
                                                   Class="d-flex flex-row rounded-0 fs-6 justify-content-between mt-1"
                                                   CloseClicked="@(() => Entity.PostLogoutRedirectUris.Remove(item))">@item</Badge>
                                        }
                                    }
                                </div>
                                <Addons>
                                    <Addon AddonType="AddonType.Body">
                                        <TextEdit Placeholder="@(L["Enter a valid URL address"])" @bind-Text="LogoutRedirectUrl" />
                                    </Addon>
                                    <Addon AddonType="AddonType.End">
                                        <Button Color="Color.Success" Clicked="@OnPostLogoutRedirectUrisClicked">@L["Add"]</Button>
                                    </Addon>
                                </Addons>
                            </Field>
                        </TabPanel>
                        <TabPanel Name="scope">
                            <SelectList Multiple
                                        style="height: 300px;"
                                        TItem="Dtos.ScopeDto"
                                        TValue="string"
                                        Data="@ScopeList"
                                        Size="Size.Large"
                                        TextField="@((item)=>item.DisplayName)"
                                        ValueField="@((item)=>item.Name)"
                                        @bind-SelectedValues="@SelectedScopeList">
                            </SelectList>
                        </TabPanel>
                    </Content>
                </Tabs>
            </Validations>
        </ModalBody>
        <ModalFooter>
            <Button Color="Color.Primary" Outline Clicked="CloseAsync">@L["Cancel"]</Button>
            <Button Color="Color.Primary" Clicked="SaveAsync">@L["Save"]</Button>
        </ModalFooter>
    </ModalContent>
</Modal>